home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / NRDUMP.C < prev    next >
Text File  |  1993-08-09  |  3KB  |  111 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "config.h"
  4. #ifdef NETROM
  5. #include "mbuf.h"
  6. #include "netrom.h"
  7. #include "nr4.h"
  8. #include "trace.h"
  9.  
  10. /* Display NET/ROM network and transport headers */
  11. void
  12. netrom_dump(FILE *fp,struct mbuf **bpp,int check)
  13. {
  14.     char src[AXALEN], dest[AXALEN], tmp[AXBUF], tmp1[AXBUF], thdr[NR4MINHDR];
  15.     char space[] = "         ";
  16.     int i;
  17.  
  18.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  19.         return;
  20.     /* See if it is a routing broadcast */
  21.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  22.         (void)PULLCHAR(bpp);        /* Signature */
  23.         pullup(bpp,tmp,ALEN);
  24.         tmp[ALEN] = '\0';
  25.         trprintf(fp,"NET/ROM Routing: %s\n",tmp);
  26.         for(i = 0;i < NRDESTPERPACK;i++) {
  27.             if (pullup(bpp,src,AXALEN) < AXALEN)
  28.                 break;
  29.             trprintf(fp,"%20s",pax25(tmp,src));
  30.             pullup(bpp,tmp,ALEN);
  31.             tmp[ALEN] = '\0';
  32.             trprintf(fp,"%8s",tmp);
  33.             pullup(bpp,src,AXALEN);
  34.             trprintf(fp,"%16s",pax25(tmp,src));
  35.             tmp[0] = PULLCHAR(bpp);
  36.             trprintf(fp,"%7u\n",uchar(tmp[0]));
  37.         }
  38.         return;
  39.     }
  40.     /* Decode network layer */
  41.     pullup(bpp,src,AXALEN);
  42.     pullup(bpp,dest,AXALEN);
  43.     i = PULLCHAR(bpp);
  44.  
  45.     trprintf(fp,"NET/ROM: %s->%s ttl %d\n",
  46.         pax25(tmp,src),pax25(tmp1,dest),i);
  47.  
  48.     /* Read first five bytes of "transport" header */
  49.     pullup(bpp,thdr,NR4MINHDR);
  50.     switch(thdr[4] & NR4OPCODE){
  51.      case NR4OPPID:    /* network PID extension */
  52.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  53.              ip_dump(fp,bpp,check) ;
  54.             return;
  55.         }
  56.          else
  57.             trprintf(fp,"%sprotocol family %x, proto %x",
  58.                 space,uchar(thdr[0]),uchar(thdr[1])) ;
  59.          break ;
  60.     case NR4OPCONRQ:    /* Connect request */
  61.         i = PULLCHAR(bpp);
  62.         pullup(bpp,src,AXALEN);
  63.         pullup(bpp,dest,AXALEN);
  64.         trprintf(fp,"%sconn rqst: ckt %d/%d wnd %d %s@%s",
  65.             space,
  66.             uchar(thdr[0]), uchar(thdr[1]),i,
  67.             pax25(tmp,src),pax25(tmp1,dest));
  68.         break;
  69.     case NR4OPCONAK:    /* Connect acknowledgement */
  70.         i = PULLCHAR(bpp);
  71.         trprintf(fp,"%sconn ack: ur ckt %d/%d my ckt %d/%d wnd %d",
  72.             space,
  73.             uchar(thdr[0]), uchar(thdr[1]),
  74.             uchar(thdr[2]), uchar(thdr[3]), i);
  75.         break;
  76.     case NR4OPDISRQ:    /* Disconnect request */
  77.         trprintf(fp,"%sdisc: ckt %d/%d",
  78.             space,
  79.             uchar(thdr[0]),uchar(thdr[1]));
  80.         break;
  81.     case NR4OPDISAK:    /* Disconnect acknowledgement */
  82.         trprintf(fp,"%sdisc ack: ckt %d/%d",
  83.             space,
  84.             uchar(thdr[0]),uchar(thdr[1]));
  85.         break;
  86.     case NR4OPINFO:    /* Information (data) */
  87.         trprintf(fp,"%sinfo: ckt %d/%d txseq %d rxseq %d",
  88.             space,
  89.             uchar(thdr[0]), uchar(thdr[1]),
  90.             uchar(thdr[2]), uchar(thdr[3]));
  91.         break;
  92.     case NR4OPACK:    /* Information acknowledgement */
  93.         trprintf(fp,"%sinfo ack: ckt %d/%d txseq %d rxseq %d",
  94.             space,
  95.             uchar(thdr[0]),uchar(thdr[1]),
  96.             uchar(thdr[2]), uchar(thdr[3]));
  97.         break;
  98.     default:
  99.         trprintf(fp,"%sunknown transport type %d",space,thdr[4] & 0x0f) ;
  100.         break;
  101.     }
  102.     if(thdr[4] & NR4CHOKE)
  103.         trprintf(fp," CHOKE");
  104.     if(thdr[4] & NR4NAK)
  105.         trprintf(fp," NAK");
  106.     if(thdr[4] & NR4MORE)
  107.         trprintf(fp," MORE");
  108.     trprintf(fp,"\n");
  109. }
  110.  
  111. #endif /* NETROM */